# Definition for singly-linked list.
from 算法.high.queue.queue import list_toqueue, print_que, ListNode


class Solution:
    def sortList(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if head == None:
            return None
        value_list = []
        while head!=None:
            value_list.append(head.val)
            head = head.next
        if len(value_list) == 1:
            return ListNode(value_list[0])
        value_list.sort()
        top = ListNode(value_list[0])
        q = top
        for value in value_list[1:]:
            q.next = ListNode(value)
            q = q.next
        return top
    

    
def main():
    sol = Solution()
    print_que(sol.sortList(list_toqueue([4,2,1,3])))


if __name__ == '__main__':
    main()